import { sm2, sm3, sm4 } from 'sm-crypto'

const sm2PublicKey = "03a9a61546af3a887b815d277c61b9e6d26cabe40a93268aac7873f1bfa9e2357a"
const sm2PrivateKey = ""
const sm4Key = "46462a25214b4324455723786d373737"

const cipher = {
    sm2Encrypt(data: string): string {
        return sm2.doEncrypt(data, sm2PublicKey, 1)
    },
    sm2Decrypt(data: string | null): string {
        if (data === null) {
            return ""
        }
        return sm2.doDecrypt(data, sm2PrivateKey, 1)
    },
    sm3Encrypt(data: string): string {
        return sm3(data)
    },
    sm4Encrypt(data: string): string {
        return sm4.encrypt(data, sm4Key, { mode: 'cbc', iv: sm4Key })
    },
    sm4Decrypt(data: string | null): string {
        if (data === null) {
            return ""
        }
        return sm4.decrypt(data, sm4Key, { mode: 'cbc', iv: sm4Key })
    }
}

export default cipher